package com.example.demo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by yls on 2018/11/6.
 */

public class MyReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("MyReceiver", "onReceive"+intent.getAction() );


        int state = NetUtil.getNetState(context);
        switch (state){
            case NetUtil.NET_MOBI:
                Toast.makeText(context,"移动网络可用",Toast.LENGTH_SHORT).show();
                break;
            case NetUtil.NET_WIFI:
                Toast.makeText(context,"WIFI网络可用",Toast.LENGTH_SHORT).show();
                break;
            case NetUtil.NET_NONE:
                Toast.makeText(context,"网络不可用",Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
